package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.contracttemplatefield.LindiContractTemplateFieldQueryVO;
import com.minimalist.common.entity.lindi.vo.contracttemplatefield.LindiContractTemplateFieldVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiContractTemplateFieldService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 林地指标平台_合同模板字段控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标平台_合同模板字段管理")
@RequestMapping("/lindi/contractTemplateField")
public class LindiContractTemplateFieldController{

    @Autowired
    private LindiContractTemplateFieldService service;

    @PostMapping("/addContractTemplateField")
    @Operation(summary = "添加合同模板字段")
    public R<?> addContractTemplateField(
            @RequestBody @Validated(Add.class)
            LindiContractTemplateFieldVO contractTemplateFieldVO){
        service.addContractTemplateField(contractTemplateFieldVO);
        return R.ok();
    }

    @DeleteMapping("/deleteContractTemplateFieldByContractTemplateFieldId")
    @Operation(summary = "删除合同模板字段 -> 根据合同模板字段ID删除")
    public R<?> deleteContractTemplateFieldByContractTemplateFieldId(
            @RequestParam("contractTemplateFieldId")
            @NotNull(message = "合同模板字段ID不能为空")
            @Parameter(name = "contractTemplateFieldId", required = true, description = "合同模板字段ID")
            Long contractTemplateFieldId){
        service.deleteContractTemplateFieldByContractTemplateFieldId(contractTemplateFieldId);
        return R.ok();
    }

    @PutMapping("/updateContractTemplateFieldByContractTemplateFieldId")
    @Operation(summary = "修改合同模板字段")
    public R<?> updateContractTemplateFieldByContractTemplateFieldId(
            @RequestBody @Validated(Update.class)
            LindiContractTemplateFieldVO contractTemplateFieldVO){
        service.updateContractTemplateFieldByContractTemplateFieldId(contractTemplateFieldVO);
        return R.ok();
    }

    @GetMapping("/getPageContractTemplateFieldList")
    @Operation(summary = "查询合同模板字段列表(分页)")
    public R<PageResp<LindiContractTemplateFieldVO>> getPageContractTemplateFieldList(
            @RequestBody LindiContractTemplateFieldQueryVO queryVO){
        return R.ok(service.getPageContractTemplateFieldList(queryVO));
    }

    @GetMapping("/getContractTemplateFieldByContractTemplateFieldId/{contractTemplateFieldId}")
    @Operation(summary = "根据合同模板字段ID查询合同模板字段")
    public R<LindiContractTemplateFieldVO> getContractTemplateFieldByContractTemplateFieldId(
            @PathVariable(value = "contractTemplateFieldId")
            @NotNull(message = "合同模板字段ID不能为空")
            @Parameter(name = "contractTemplateFieldId", description = "合同模板字段ID", required = true)
            Long contractTemplateFieldId){
        return R.ok(service.getContractTemplateFieldByContractTemplateFieldId(contractTemplateFieldId));
    }
}